﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>页面访问时间限制</title>
    <script type="text/javascript">
        let limit="1:02";                      //设置剩余的时间
        let tmpTime=limit.split(":");          //将分和秒切割开
        let myTime=tmpTime[0]*60+tmpTime[1]*1;     //获取剩余的秒数
        
        function calTime(){
            if(myTime === 1){
                window.location = "www.baidu.com";
            }else{
                myTime -= 1;
                curmin = Math.floor(myTime / 60);
                cursec = myTime;
                if(curmin !== 0){
                    curtime = "你只有" + curmin + "分钟的时间保存此页";
                }else{
                    curtime = "你只有" + cursec + "秒的时间保存此页,请尽快保存";
                }
                setTimeout("calTime()",1000);   // 设置定时器，不断变化提示时间
                document.form1.txttime.value = curtime; // 在文本框中显示剩余时间
            }
        }
    </script>
</head>
<body bgcolor="#fabaaa" onload="calTime()">
<form name="form1">
    <p><input type="text" name="txttime" size="40" />
    </p>
</form>
</body>
</html>